<?php

class Destination_model extends  Model {


    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }


    public function get_destination_list($limit,$start) {
        $destination_sql = "SELECT *
                                    FROM tbl_destinations";
        $destination = $this->db->query($destination_sql);
         try{
            $destination_sql = "SELECT *
                                    FROM tbl_destinations";
            $destination_sql.= " limit ".$start.",".$limit;
        $destination = $this->db->query($destination_sql);
        if($destination->num_rows() > 0) {
                 return $destination_result = $destination->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_destination_list_forhotelform() {        
         try{
            $destination_sql = "SELECT *
                                    FROM tbl_destinations";
        $destination = $this->db->query($destination_sql);
        if($destination->num_rows() > 0) {
                 return $destination_result = $destination->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_destination_list_count() {
         try{
            $destination_sql = "SELECT count(*) as count
                                    FROM tbl_destinations";
        $destination = $this->db->query($destination_sql);
        if($destination->num_rows() > 0) {
                  $destination_result = $destination->row_array();
                  return $destination_result["count"];
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
     
    public function get_destination_list_forhoteledit($hotel_id) {

         try{
            $destination_sql = "SELECT *  ,  (select destid from tbl_hoteldestinations b  where b.Hid={$hotel_id} and b.destid=a.id) as checkval FROM tbl_destinations a
                                    
                       ";
        $destination = $this->db->query($destination_sql);
        if($destination->num_rows() > 0) {
                 return $destination_result = $destination->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
     public function addnewdestination($acomdationdetails) {
        try{
                $destination_sql = "INSERT INTO tbl_destinations
                                              (
                                               destdesc,
                                               status
                                              )
                                       VALUES (?,?)";
               $this->db->query($destination_sql, array(
                                             $acomdationdetails['destdesc'],
                                             $acomdationdetails['status'],

                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

    public function get_destination_details($destid)
    {
        
         try{
           $destination_sql = "SELECT *
                                    FROM tbl_destinations where id=?";
        $destination = $this->db->query($destination_sql, array($destid));
        if($destination->num_rows() > 0) {
            print_r($destination->row_array());
                 return $destination_result = $destination->row_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
     public function doeditdestination($acomdationdetails) {
      //   print_r($acomdationdetails);exit;
        try{
                $destination_sql = "update tbl_destinations set destdesc=?,status=?  where id=?";
               $this->db->query($destination_sql, array(
                                             $acomdationdetails['destdesc'],
                                             $acomdationdetails['status'],
                                             $acomdationdetails['id']
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

      public function deletedestination($destid) {
      //   print_r($acomdationdetails);exit;
        try{
                $destination_sql = "delete from tbl_destinations  where id=?";
               $this->db->query($destination_sql, array($destid
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }  

    public function addnewfeatureddestination($acomdationdetails) {
        try{            
            $destination_sql = "INSERT INTO tbl_featureddestination
                                            (
                                            `title`,
                                            `desc`,
                                            `date_from`,
                                            `date_to`,
                                            `isactive`
                                            )
                                    VALUES (?,?,?,?,?)";
            $res=$this->db->query($destination_sql, array(
                                            $acomdationdetails['title'],
                                            $acomdationdetails['desc'],
                                            $acomdationdetails['date_from'],
                                            $acomdationdetails['date_to'],
                                            $acomdationdetails['isactive']

            ));

            $res2=$this->db->getLastInsertId();             
            $last_id=$res2->result_array();
            return ($last_id[0]['last_id']);
               

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function is_featured_destination_available()
    {        
         try{
           $destination_sql = "SELECT id
                                    FROM tbl_featureddestination order by `id` desc limit 1";
        $destination = $this->db->query($destination_sql);
        if($destination->num_rows() > 0) {
                 return $destination_result = $destination->row_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_featured_destination_details($featureddestid)
    {
        
         try{
           $destination_sql = "SELECT *
                                    FROM tbl_featureddestination where `id`=?";
        $destination = $this->db->query($destination_sql, array($featureddestid));
        if($destination->num_rows() > 0) {
                 return $destination_result = $destination->row_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
     public function doeditfeaturedacomdation($acomdationdetails) {
      //   print_r($acomdationdetails);exit;
        try{
                $destination_sql = "update tbl_featureddestination set `title`=?,`desc`=?,`date_from`=?,`date_to`=?,`isactive`=?  where `id`=?";
               $this->db->query($destination_sql, array(
                                                        $acomdationdetails['title'],
                                                        $acomdationdetails['desc'],
                                                        $acomdationdetails['date_from'],
                                                        $acomdationdetails['date_to'],
                                                        $acomdationdetails['isactive'],
                                                        $acomdationdetails['id']
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }   
    
}
?>
